﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class JobExecute : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            cbxJobList.DataSource = clsSQLOperations.GetJobList();
            cbxJobList.DataValueField = "Urn";
            cbxJobList.DataTextField = "Name";
            cbxJobList.DataBind();
        }
    }
    protected void btnStartJob_Click(object sender, EventArgs e)
    {
        bulResults.Items.Clear();        
        foreach (ListItem li in cbxJobList.Items)
        {
            if (li.Selected)
            {
                clsSQLOperations.ActionResult result = clsSQLOperations.StartJob(li.Text);
                if (result == clsSQLOperations.ActionResult.Success)
                {
                    bulResults.Items.Add(li.Text + " started successfully.");
                }
                else
                {
                    bulResults.Items.Add(li.Text + " failed to start.");
                }
                bulResults.DataBind();
            }
        }  
    }
}
